package com.huishu.user.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huishu.commons.config.cache.RedisUtil;
import com.huishu.commons.pojo.Result;
import com.huishu.user.pojo.model.ClauseDO;
import com.huishu.user.service.ClauseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author generator@ljj
 * @since 2023-04-14
 */
@RestController
@RequestMapping("/clause")
public class ClauseController {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private ClauseService clauseService;

    @GetMapping("/findByType/{type}")
    public Result findByType(@PathVariable Integer type) {
        LambdaQueryWrapper<ClauseDO> queryWrapper = Wrappers.lambdaQuery(ClauseDO.class)
                .eq(ClauseDO::getType, type);
        return Result.success(clauseService.getOne(queryWrapper));
    }

    @PostMapping("/createOrUpdate")
    public Result createOrUpdate(@RequestBody ClauseDO clauseDO) {
        return clauseService.saveOrUpdate(clauseDO) ? Result.success() : Result.fail();
    }
}
